﻿//作者：王晓
//功能：扩展ComboBox

/// <reference path="/ExtJs/adapter/ext-base.js"/>
/// <reference path="/ExtJs/ext-all-debug.js"/>
Ext.namespace('Yaxunsoft', 'Yaxunsoft.Framework');
Yaxunsoft.Framework.BaseComboBox = Ext.extend(Ext.form.ComboBox, {
    initComponent: function() {
        Yaxunsoft.Framework.BaseComboBox.superclass.initComponent.call(this);
    },
    onRender: function(ct, position) {
        Yaxunsoft.Framework.BaseComboBox.superclass.onRender.call(this, ct, position);
        if (this.name) {
            this.postField = this.el.insertSibling({ tag: 'input', type: 'hidden', name: this.name + "_Id", id: (this.hiddenName || this.name) + "_Id" },
                    'before', true);
            this.postField.value =
                this.postField !== undefined ? this.postField :
            //          this.id = this.name;
            this.el.dom.removeAttribute('name');
            this.hiddenField.removeAttribute('name');
        }
    },
    setValue: function(v) {
        if (v != null) {
            if (typeof (v) == "object") {
                v = v.Id;
            }
        } else {
            return "";
        }


        this.postField.value = v;
        Yaxunsoft.Framework.BaseComboBox.superclass.setValue.call(this, v);
    }
});

Yaxunsoft.Framework.BaseComboBoxDays = Ext.extend(Ext.form.ComboBox, {
    initComponent: function () {
        Yaxunsoft.Framework.BaseComboBoxDays.superclass.initComponent.call(this);
    },
    onRender: function (ct, position) {
        Yaxunsoft.Framework.BaseComboBoxDays.superclass.onRender.call(this, ct, position);
        if (this.name) {
            this.postField = this.el.insertSibling({ tag: 'input', type: 'hidden', name: this.name + "_Id", id: (this.hiddenName || this.name) + "_Id" },
                    'before', true);
            this.postField.value =
                this.postField !== undefined ? this.postField :
            //          this.id = this.name;
            this.el.dom.removeAttribute('name');
            this.hiddenField.removeAttribute('name');
        }
    },
    setValue: function (v) {
        if (v != null) {
            if (typeof (v) == "object") {
                ids = v.ID;
                v = v.Days;
            }
            else {
                ids = v;
            }
        } else {
            return "";
        }


        this.postField.value = ids;
        Yaxunsoft.Framework.BaseComboBoxDays.superclass.setValue.call(this, v);
    }
});

